﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 观察者模式
{
    class Cat
    {
        public string Color { get; set; }
        public string Name { get; set; }
        // 声明一个事件，发布一个消息
        public event Action action;
        //public Action action;

        public Cat() { }
        public Cat(string color, string name)
        {
            Color = color;
            Name = name;
        }

        public void CatComing(Mouse m1, Mouse m2, Mouse m3)
        {
            Console.WriteLine(Color + "的" + Name + "来了，喵喵喵~");
            m1.RunAway();
            m2.RunAway();
            m3.RunAway();
        }

        public void CatComing()
        {
            Console.WriteLine(Color + "的" + Name + "来了，喵喵喵~");
            if (action != null)
            {
                action();   //执行事件
            }
        }
    }
}
